//: exceptions/InheritingExceptions.java
// Creating your own exceptions.
package exceptions;
class SimpleException extends Exception {}

public class InheritingExceptions {
  public void f() throws SimpleException {//声明异常，表示可能抛出异常
    System.out.println("Throw SimpleException from f()");
    throw new SimpleException();//真正抛出异常
  }
  public static void main(String[] args) {
    InheritingExceptions sed = new InheritingExceptions();
    try {//由于声明了异常，必须处理，要么抛出，要么处理
      sed.f();
    } catch(SimpleException e) {//当声明了异常的try块确实抛出了这个异常，就运行改catch块
      System.out.println("Caught it!");
    }
  }
} /* Output:
Throw SimpleException from f()
Caught it!
*///:~
